#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int comper(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int *)p2;
}

int main()
{
	int n = 0;
	scanf("%d", &n);
	long arr[1000];
	for (int i = 0; i < n; i++)
	{
		scanf("%ld", &arr[i]);
	}
	qsort(arr, n, sizeof(long), comper);

	long sum1 = 0, sum2 = 0;
	int left = 0, right = n - 1;
	while (left <= right)
	{
		if (sum1 <=sum2)
		{
			sum1 += arr[left];
			left++;
		}
		else
		{
			sum2+= arr[right];
			right--;
		}
	}
	if (sum1 - sum2 >= 0)
		printf("%d", sum1 - sum2);
	else
		printf("%d", sum2 - sum1);
	return 0;
}